<extend name="./Application/Common/View/block/base.php" />
<block name="header">
    <include file="./Application/Admin/View/block/easyui_header.php" />
    <link rel="stylesheet" type="text/css" href="/Public/uploadfy/uploadify.css" />
    <script type="text/javascript" src="/Public/uploadfy/jquery.uploadify.min.js"></script>
    <style>
        #dg{
            height: 100%;;
        }
    </style>
</block>
<block name="bdoy">
    <body>
    <table id="grid_waterele_log"></table>
    <div id="grid_waterele_log_ToolBar" style="padding:5px;height:auto">
        <div style="margin-bottom:5px">
            <a id="btnsetcheckwaterele" href="#" class="easyui-linkbutton" iconCls="icon-search" plain="true">审核</a>
            <a id="btnAddWaterelelog" href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true">增加</a>
            <a id="btneditWaterloglog" href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true">编辑</a>
            <a id="btnDelWaterelelog" href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除</a>
            <a id="btnSearchWaterelelog" href="#" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
            <a id="btnReload" href="#" class="easyui-linkbutton" iconCls="icon-reload" plain="true" onclick="$('#grid_waterele_log').datagrid({url:'/Manage/AdminCsdtWater/log_get_all',queryParams:{'ischecked':0,page:1,rows:20}})">重载</a>
        </div>
        <div id="queryParamZone_waterele_log">
            <form id="queryForm_Waterelelog" method="post" action="">
                <div>
                    <input type="hidden" name="pumpid" id="search_form_station_id"/>
                    <table>
                        <tr>
                            <td>调蓄池：</td>
                            <td><input id="ps_id_combox_2" name="ps_id"></td>
                            <td>水表：</td>
                            <td><select class="easyui-combobox waterele_select" name="eleid" valueField="id" textField="we_number" data-options="prompt:'{:LANG('pls_input')}'" style="width: 140px;"></select></td>
                            <td>从：</td>
                            <td><input class="easyui-datebox" name="start" style="width: 100px;"></td>
                            <td>到：</td>
                            <td><input class="easyui-datebox" name="end" style="width: 100px;"></td>
                            <td><span><a id="btnQueryWaterelelog" href="#" class="easyui-linkbutton" iconCls="icon-search">查询</a></span></td>
                            <td><a href="#" class="easyui-linkbutton" iconCls="icon-undo" onclick="javascript:$('#query_form').form('clear');">重置</a></td>
                        </tr>
                    </table>

                </div>
            </form>
        </div>
    </div>
    <div id="waterelelogDlg" class="easyui-dialog" title="" style="width:650px;height:300px;padding:10px" buttons="#dlg-buttons-waterele-log" closed="true" resizable="true">
        <form id="waterelelogForm" method="post" action="">
            <input id="saveflag_waterele_log" name="saveflag_waterele_log" type="hidden" value="add"/>
            <input id="waterele_id" type="hidden" name="id" />
            <table border="0">
                <tr>
                    <td align="right">调蓄池</td>
                    <td><input id="ps_id_combox_3" required="true" name="station"></td>
                    <td>水表：</td>
                    <td>
                        <select class="easyui-combobox waterele_select" id="eleid" name="eleid" valueField="id" textField="we_number" data-options="prompt:'{:LANG('pls_input')}',required:true" style="width: 140px;">

                        </select>
                    </td>
                </tr>
                <tr>
                    <td align="right">操作日期：</td>
                    <td>
                        <input class="easyui-datetimebox" type="text" name="date" required data-options="validType:'md[\'10/11/2012 2:33:22\']'"></input>
                    </td>
                    <td align="right">水表读数：</td>
                    <td>
                        <input class="easyui-numberbox"  type="text" name="waterdegrees" precision="3"></input>
                    </td>
                </tr>
            </table>
        </form>
    </div>
    <div id="dlg-buttons-waterele-log" style="text-align: center;">
        <a href="#" class="easyui-linkbutton" iconCls="icon-save" onclick="javascript:submitwaterelelogForm();">保存</a>
    </div>
    <form id="batchDelForm" method="post">
    </form>
    </body>
</block>
<block name="footExtendJs">
    <script type="text/javascript">
        //$.noConflict();
        $(window).resize(function() {
            $('#grid_waterele_log').datagrid('resize');
        });

        function clearwaterelelogForm(){
            $('#waterelelogForm').form('clear');
        }

        function clearQueryParamZone(){
            $('#queryForm_Waterelelog').form('clear');
        }

        $(function(){
            $('#ps_id_combox_2').combobox({
                url:'/Manage/AdminCsdt/get_all_combox',
                valueField:'id',
                textField:'name',
                width:180,
                onChange: function (newValue, oldValue) {
                    $('.waterele_select').combobox('clear');
                    $('.waterele_select').combobox('reload', '/Manage/AdminCsdtWater/get_all_water?ps_id='+newValue);
                }
            });
            $('#ps_id_combox_3').combobox({
                url:'/Manage/AdminCsdt/get_all_combox',
                valueField:'id',
                textField:'name',
                width:180,
                onChange: function (newValue, oldValue) {
                    $('#eleid').combobox('clear');
                    $('#eleid').combobox('reload','/Manage/AdminCsdtWater/get_all_water?ps_id='+newValue);
                }
            });
            $('#grid_waterele_log').datagrid({
                //title:'水表',
                width: '100%',
                //height: 400,
                fit: true,
                nowrap: false,
                striped: true,
                collapsible:false,
                url:'/Manage/AdminCsdtWater/log_get_all',
                queryParams:{'ischecked':0,page:1,rows:20},
                method:'get',
                pageNumber:1,
                pageSize:20,
                idField:'id',
                sortName: 'id',
                sortOrder: 'desc',
                remoteSort: false,
                columns:[[
                    {field:'id',title:'序号',width:60,checkbox:true},
                    {field:'we_name',title:'水表名称',width:100,align:'center'},
                    {field:'sta_name',title:'调蓄池名称',width:180,align:'center'},
                    {field:'date',title:'填报日期',width:140,align:'center'},
                    {field:'waterdegrees',title:'水表读数',width:140,align:'center'},

                ]],
                pagination:true,
                rownumbers:true,
                singleSelect:true,
                toolbar: '#grid_waterele_log_ToolBar',
                onDblClickRow: function(rowIndex, rowData) {
                    var selected = $('#grid_waterele_log').datagrid('getSelected');
                    if($('#single').is(":hidden")){
                        editWaterelelog(rowData.id);
                    }else{
                        var rows = $('#grid_waterele_log').datagrid('getSelections');
                        if(selected){
                            if(selected.id == rowData.id){
                                editWaterelelog(rowData.id);
                            }else{
                                $.messager.alert('提示','当前选择了多条信息，不可以编辑！','error');
                            }
                        }else{
                            editWaterelelog(rowData.id);
                        }
                    }
                },
                onSelect: function(rowIndex, rowData) {
                    var now_rows = jQuery('#grid_waterele_log').datagrid('getSelections');
                    if(now_rows.length > 1){
                        $("#btneditWaterloglog").linkbutton('disable');
                    }
                },
                onUnselect: function(rowIndex, rowData) {
                    var now_rows = jQuery('#grid_waterele_log').datagrid('getSelections');
                    if(now_rows.length < 2){
                        $("#btneditWaterloglog").linkbutton('enable');
                    }
                },
                onLoadSuccess: function(data) {
                    $(this).datagrid('resize');

                }
            });
            var p = $('#grid_waterele_log').datagrid('getPager');
            $(p).pagination({
                onBeforeRefresh:function(){
                    //alert('before refresh');
                }
            });

            $('#btnAddWaterelelog').click(function() {
                clearwaterelelogForm();
                $("#saveflag_waterele_log").val("add");
                $('#ps_id_combox_3').combobox({
                    url:'/Manage/AdminCsdt/get_all_combox',
                    valueField:'id',
                    textField:'name',
                });
                $('#waterelelogDlg').dialog({title:'录入泵机运行记录信息',modal:true});
                $('#waterelelogDlg').dialog("open");
            });
            $('#btneditWaterloglog').click(function() {
                var selected = $('#grid_waterele_log').datagrid('getSelected');
                if($('#single').is(":hidden")){
                    if (selected) {
                        editWaterelelog(selected.id);
                    }
                }else{
                    var rows = $('#grid_waterele_log').datagrid('getSelections');
                    if(rows.length == 1 || rows.length == 0){
                        if (selected) {
                            editWaterelelog(selected.id);
                        }
                        else{
                            $.messager.show({title: "提示",msg: "请选中一条信息，再进行编辑!"});
                        }
                    }else{
                        $.messager.alert('提示','当前选择了多条信息，不可以编辑！','error');
                        singleToggle();
                    }
                }
            });
            $('#btnDelWaterelelog').click(function() {

                var ids = [];
                var rows = $('#grid_waterele_log').datagrid('getSelections');
                for ( var i = 0; i < rows.length; i++) {
                    ids.push(rows[i].id);
                }
                if ((ids != null) && (ids.length > 0)) {
                    $.messager.confirm('请确认', '你确定要删除吗？', function(r) {
                        if (r) {

                            $('#batchDelForm').ajaxSubmit({
                                url:"/Manage/AdminCsdtWater/log_deleteArray",
                                data:{'ids':ids.join(',')},
                                dataType:'json',
                                success: function(data) {
                                    if (data.status==1) {
                                        $('#grid_waterele_log').datagrid('reload');
                                        $('#grid_waterele_log').datagrid("unselectAll");
                                        $.messager.show({title:'提示',msg:'删除成功！',showType:'slide'});
                                    }
                                    else $.messager.alert('提示','删除失败！','error');
                                }
                            });

                        }
                    });
                }

            });
            $('#btnSearchWaterelelog').click(function() {
                $('#queryParamZone_waterele_log').toggle();
                if($('#queryParamZone_waterele_log').is(":hidden")){
                    clearQueryParamZone();
                }
                $('#grid_waterele_log').datagrid("resize");
            });

            $('#btnQueryWaterelelog').click(function() {
                var obj = $('#queryForm_Waterelelog').serializeJson();
                obj['ischecked'] = 0;
                $('#grid_waterele_log').datagrid('load',obj);
            });

            $('#btnsetcheckwaterele').click(function() {
                var selected = $('#grid_waterele_log').datagrid('getSelections');
                var ids = get_ids_from_json(selected);
                var url = '/Manage/AdminCsdtWater/set_check';
                $.post(url,{'ids':ids},function(data){
                    $.messager.show({title:'提示',msg:'审核成功！',showType:'slide'});
                    $('#grid_waterele_log').datagrid({url:'/Manage/AdminCsdtWater/log_get_all',queryParams:{'csdtid':$('#csdtstation_id').val(),'ischecked':0,page:1,rows:20}})
                });
            });

            $('#queryParamZone_waterele_log').hide();
            $('#single').hide();


        });

        function editWaterelelog(id) {
            if(id!=""){
                $("#saveflag_waterele_log").val("update");
            }else{
                clearwaterelelogForm();
                $("#saveflag_waterele_log").val("add");
                return;
            }
            $.ajax({url:"/Manage/AdminCsdtWater/get_obj_log_json",data:{id:id},dataType:"json",success:function(json, textStatus){
                $('#eleid').combobox('reload','/Manage/AdminCsdtWater/get_all_water?ps_id='+json.station);
                $('#waterelelogForm').form('load',{
                    "id": json.id,
                    "date": json.date,
                    'station' : json.station,
                    "eleid": json.eleid,
                    "pump_pfa": json.pump_pfa,
                    "pump_rta": json.pump_rta,
                    "pump_lta": json.pump_lta,
                    "pump_fa": json.pump_fa,
                    "pump_nfa": json.pump_nfa,
                    "pump_ra": json.pump_ra,
                    "pump_waterdegrees": json.pump_waterdegrees
                });
                $('#waterelelogDlg').dialog({title:'编辑水表信息',modal:true});
                $('#waterelelogDlg').dialog("open");
                setFormFocus('#waterelelogForm');
            },error:function(XMLHttpRequest, textStatus, errorThrown) {
                relogin(XMLHttpRequest, textStatus, errorThrown);
            }});
        }

        function submitwaterelelogForm() {
            if ($('#waterelelogForm').form('validate')) {
                var submitflag = $("#saveflag_waterele_log").val();
                var url = "";
                if (submitflag === "add")
                    url = "/Manage/AdminCsdtWater/log_add";
                if (submitflag === "update")
                    url = "/Manage/AdminCsdtWater/log_edit";
                $('#waterelelogForm').ajaxSubmit({
                    url:url,
                    dataType:'json',
                    success: function(data) {
                        if (data.status==1) {
                            if (submitflag === "add") $('#grid_waterele_log').datagrid('load');
                            if (submitflag === "update") $('#grid_waterele_log').datagrid('reload');
                            $('#waterelelogDlg').dialog("close");
                            $.messager.show({title:'提示',msg:'保存成功！',showType:'slide'});
                        }
                        else $.messager.alert('提示','操作失败！','error');
                    }
                });
            }else{
                console.log('no valdate');
            }
        }
    </script>
</block>
